<?php
/**
**对接酷秀
**date 2015-12-04
**user by pzp
账号 sdpftcs
密钥  97706d9051297ec83d1f3aff32d9e83a
接口地址  http://new.coolshow.cn/api/mobile/
**/

class KuXiu{
	
	private $uname;
	private $pass;
	private $url = 'http://new.coolshow.cn/api/mobile/';
	
	public function __construct(){
		$this->uname = 'sdpftcs';
		$this->pass = '97706d9051297ec83d1f3aff32d9e83a';
	}
	
	
	//登录接口
	public function checkuser(){	
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'checkuser',
		);
		$request_arr  = $this->Mosaic_data($array);
		return $request_arr;		
	}
	
	//产品列表
	public function product_list(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'product_list',
			'type'		=> 'shopname',
			'keyword'	=> '',
			'page'		=> 1,
			'size'		=> ''
		);
		$request_arr  = $this->Mosaic_data($array);
		return simplexml_load_string($request_arr);
	}
	
	//产品详情
	public function product_info(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'product_info',
			'goodid'	=> '201507171645418370',
		);
		$request_arr  = $this->Mosaic_data($array);
		return simplexml_load_string($request_arr);
	}
	
	//发码接口
	public function order_send(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'order_send',
			'goodid'	=> '201507171645418370',
			'goodnum'	=> 2,
			'ordername'	=> '20151208001002', //订单号
			'tel'		=> '15959110796',
			'tuanname'	=> '票付通',
			'salesPeople'	=> '票付通',
			'salesPrice'	=> '15',
			'linkName'		=> '小彭',
			'idcard'		=> '350321199108230123',
			'reservationDate'	=> '2015-12-08',
			'sendway'	=> 1,
			'sendmes'	=> 0
		);
		$request_arr  = $this->Mosaic_data($array);
		return simplexml_load_string($request_arr);	
	}
	
	//退款 接口
	public function refund(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'refund',
			'ordernum'	=> '14496585482554536_2',
			'locknum'	=> 1,
			'cardPwd'	=> 'KX73520272',
			'note'		=> '', 
		);
		$request_arr  = $this->Mosaic_data($array);
		return simplexml_load_string($request_arr);
		
	}
	
	//重发接口
	public function resend(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'resend',
			'goodid'	=> '201507171645418370',
			'goodnum'	=> 2,
			'tel'		=> '15959110796', 
			'ordernum'	=> '14496585482554536_2'
		);
		$request_arr  = $this->Mosaic_data($array);
		return $request_arr;
	}
	
	//订单详情
	public function order_info(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'order_info',
			'ordernum'	=> '14496601302554334_1',
		);
		$request_arr  = $this->Mosaic_data($array);
		return simplexml_load_string($request_arr);
	}
	
	//查码接口
	public function checkcode(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'checkcode',
			'cardPwd'	=> '',
		);
		$request_arr  = $this->Mosaic_data($array);
		return $request_arr;
	}	
	
	//获取码号
	public function getcardpwd(){
		$array= array(
			'format'	=>'xml',
			'uname'		=> $this->uname,
			'pass'		=> $this->pass,
			'method'	=> 'getcardpwd',
			'orderid'	=> '',
		);
		$request_arr  = $this->Mosaic_data($array);
		return $request_arr;
	}
	
	//拼接数据
	public function Mosaic_data($request_arr){
		ksort($request_arr);
		$request_arr['sign'] = md5(md5(http_build_query($request_arr)).$this->pass);	//加密
		$request_arr = http_build_query($request_arr);
		$post_arr = $this->KX_post($request_arr);
		return $post_arr;
	}
	
	//提交数据
	public function KX_post($req_array3){
		$this_header = array("content-type: application/x-www-form-urlencoded;charset=UTF-8");
		$ch = curl_init(); 
		curl_setopt($ch,CURLOPT_HTTPHEADER,$this_header);
		curl_setopt($ch, CURLOPT_POST, 1); 
		curl_setopt($ch, CURLOPT_HEADER, 0); 
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
		curl_setopt($ch, CURLOPT_URL,$this->url); 	
		curl_setopt($ch, CURLOPT_POSTFIELDS, $req_array3); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		$result = curl_exec($ch);
		return $result;
	}
}
$KuXiu = new KuXiu();
// $checkuser = $KuXiu ->checkuser();print_r($checkuser);
// $product_list = $KuXiu ->product_list();print_r($product_list);
// $product_info = $KuXiu ->product_info();print_r($product_info);
// $order_send = $KuXiu ->order_send();print_r($order_send);
// $refund = $KuXiu ->refund();print_r($refund);
// $resend = $KuXiu ->resend();print_r($resend);
$order_info = $KuXiu ->order_info();print_r($order_info);